Imports System.Windows.Forms

Public Class MDIParent1

    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
        ' Create a new instance of the child form.

        Dim ChildForm As New Doc
        'Dim richtextbox1 As New System.Windows.Forms.RichTextBox
        Dim cmnu As New System.Windows.Forms.ContextMenuStrip
        'Dim richtextbox1 As New System.Windows.Forms.RichTextBox
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me
        m_ChildFormNumber += 1
        ChildForm.Text = "Untitled " & m_ChildFormNumber
        ChildForm.RichTextBox1.Dock = DockStyle.Fill
        ChildForm.RichTextBox1.Parent = ChildForm
        'cmnu.Parent = ChildForm
        'cmnu.Items.Add("Copy")
        'cmnu.Items.Add("Paste")
        'cmnu.Items.Add("Cut")
        ChildForm.Show()
        check_mdichild()
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
        Dim OpenFileDialog As New OpenFileDialog
        Dim document As New Doc
        ' Make it a child of this MDI form before showing it.
        document.MdiParent = Me

        With OpenFileDialog
            'Set the Filter Text
            .Filter = "Text Files (*.txt)|*.txt|" & _
                      "CSS Templates (*.css)|*.css|" & _
                  "HTML Templates (*.html)|*.html|" & _
                  "Theme Information (*.dat)|*.dat"

            'Pick Text Files to begin with
            .FilterIndex = 1

            'The Caption
            .Title = "Pick a file to open..."

            'Ensure we only get back valid filenames
            .CheckFileExists() = True
            .CheckPathExists = True
            .ValidateNames = True
            .DereferenceLinks = True

            'Set the starting dir
            .InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments

            'Show the Window
            .ShowDialog(Me)

            If .FileName <> "" Then
                'Set inital properties of the richtextbox
                'control
                'document.RichTextBox1.AutoWordSelection = True
                'document.RichTextBox1.ScrollBars = RichTextBoxScrollBars.Vertical
                'document.RichTextBox1.WordWrap = True

                'If the last three characters of the file name are
                'RTF then this is a richtext file so load it as 
                'such, else load as normal text
                
                document.RichTextBox1.LoadFile(.FileName, _
                RichTextBoxStreamType.PlainText)
                document.Visible = True
            End If
            document.Text = .FileName
        End With
        check_mdichild()


    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim name As String
        SaveFileDialog1.InitialDirectory = "C:\My Documents"
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|" & _
                  "CSS Templates (*.css)|*.css|" & _
                  "HTML Templates (*.html)|*.html|" & _
                  "Theme Information (*.dat)|*.dat"
        SaveFileDialog1.ShowDialog()
        name = SaveFileDialog1.FileName
        If name = "" Then
        Else
            For Each ChildForm As Form In Me.MdiChildren
                If ChildForm.ContainsFocus Then
                    For Each richtextbox1 As RichTextBox In ChildForm.Controls
                        richtextbox1.SaveFile(name, RichTextBoxStreamType.PlainText)
                        MsgBox("File saved as " & name)
                        ChildForm.Text = name
                    Next
                    Exit For
                End If
            Next
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Global.System.Windows.Forms.Application.Exit()
    End Sub
    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
        For Each ChildForm As Form In Me.MdiChildren
            If ChildForm.ContainsFocus Then
                For Each richtextbox1 As RichTextBox In ChildForm.Controls
                    richtextbox1.Cut() ' = richtextbox1.SelectedText
                    'My.Computer.Clipboard.SetText()
                    'richtextbox1.SelectedText
                Next
                Exit For
            End If
        Next
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
        For Each ChildForm As Form In Me.MdiChildren
            If ChildForm.ContainsFocus Then
                For Each richtextbox1 As RichTextBox In ChildForm.Controls
                    richtextbox1.Copy() ' = richtextbox1.SelectedText
                    'My.Computer.Clipboard.SetText()
                    'richtextbox1.SelectedText
                Next
                Exit For
            End If
        Next
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve information from the clipboard.
        For Each ChildForm As Form In Me.MdiChildren
            If ChildForm.ContainsFocus Then
                For Each richtextbox1 As RichTextBox In ChildForm.Controls
                    richtextbox1.Paste()
                Next
                Exit For
            End If
        Next
    End Sub

    Private Sub ToolBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolBarToolStripMenuItem.Click
        Me.ToolStrip.Visible = Me.ToolBarToolStripMenuItem.Checked
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticleToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer = 0

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        AboutBox1.Show()
    End Sub

    Private Sub DocumentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Doc.Visible = True
    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        SaveFileDialog1.InitialDirectory = "C:\My Documents"
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|" & _
                  "CSS Templates (*.css)|*.css|" & _
                  "HTML Templates (*.html)|*.html|" & _
                  "Theme Information (*.dat)|*.dat"
        SaveFileDialog1.ShowDialog()
        If SaveFileDialog1.FileName = "" Then
        Else
            For Each ChildForm As Form In Me.MdiChildren
                If ChildForm.ContainsFocus Then
                    For Each richtextbox1 As RichTextBox In ChildForm.Controls
                        Name = SaveFileDialog1.FileName
                        richtextbox1.SaveFile(Name, RichTextBoxStreamType.PlainText)
                        MsgBox("File saved as " & Name)
                        ChildForm.Text = Name
                    Next
                    Exit For
                End If
            Next
        End If

    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        Dim name As String
        SaveFileDialog1.InitialDirectory = "C:\My Documents"
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|" & _
                  "CSS Templates (*.css)|*.css|" & _
                  "Rich Text Files (*.rtf)|*.rtf|" & _
                  "XML Files (*.xml)|*.xml"
        SaveFileDialog1.ShowDialog()
        If SaveFileDialog1.FileName = "" Then
        Else
            For Each ChildForm As Form In Me.MdiChildren
                If ChildForm.ContainsFocus Then
                    For Each richtextbox1 As RichTextBox In ChildForm.Controls
                        name = SaveFileDialog1.FileName
                        richtextbox1.SaveFile(name, RichTextBoxStreamType.PlainText)
                        MsgBox("File saved as " & name)
                        ChildForm.Text = name
                    Next
                    Exit For
                End If
            Next
        End If
    End Sub

    Private Sub FileMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileMenu.Click

    End Sub

    Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Focus()
        StartPosition = FormStartPosition.CenterScreen
        If FileExist("theme.dat") Then
            DeleteFile("theme.dat")
        End If
        If FileExist("template.html") Then
            DeleteFile("template.html")
        End If
        If FileExist("template.css") Then
            DeleteFile("template.css")
        End If
        check_mdichild()
    End Sub

    Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
        MsgBox("Options not yet implemented.")
    End Sub

    Private Sub MenuStrip_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip.ItemClicked

    End Sub

    Private Sub ThemeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThemeToolStripMenuItem.Click

    End Sub

    Private Sub WizardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WizardToolStripMenuItem.Click
        Wizard.Visible = True
        clsGlobal.fram = 0
        Wizard.nextt.Enabled = True
        Wizard.finish.Enabled = False
        check_frame()
    End Sub
    Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
        For Each ChildForm As Form In Me.MdiChildren
            If ChildForm.ContainsFocus Then
                For Each richtextbox1 As RichTextBox In ChildForm.Controls
                    richtextbox1.Undo()
                Next
                Exit For
            End If
        Next
    End Sub

    Private Sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
        For Each ChildForm As Form In Me.MdiChildren
            If ChildForm.ContainsFocus Then
                For Each richtextbox1 As RichTextBox In ChildForm.Controls
                    richtextbox1.Redo()
                Next
                Exit For
            End If
        Next
    End Sub

    Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
        For Each ChildForm As Form In Me.MdiChildren
            If ChildForm.ContainsFocus Then
                For Each richtextbox1 As RichTextBox In ChildForm.Controls
                    richtextbox1.SelectAll()
                Next
                Exit For
            End If
        Next
    End Sub

    Private Sub PrintSetupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk

    End Sub

    Private Sub IndexToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("No help available yet. Look for help in future versions. Ask questions on the Eblah forum.")
    End Sub

    Private Sub SearchToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        ActiveMdiChild.Close()
    End Sub

    Private Sub ContentsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContentsToolStripMenuItem.Click
        Help.Visible = True
    End Sub
End Class
